<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue2.js"></script>
</head>
<body>
    <div id="app">
        <father></father>
    </div>
    <template id="father">
        <div class="father">
            <p>我是父组件叫{{fname}}</p>
            <son></son>
        <daughter></daughter>
        </div>
        
    </template>
    <template id="son">
        <div class="son">
            <p>我是子组件之一叫做{{sname}}</p>
            <input type="button" value="告诉我妹妹我女朋友叫" @click="tellname">
        </div>
    </template>
    <template id="daughter">
        <div class="daughter">
            <p>我是子组件之一叫做{{dname}}</p>
            <p>今天我哥哥告诉我 他有女朋友了 叫做{{saozi}}</p>
        </div>
    </template>
</body>
<script>
    // 创建事件总线的实例对象
    var bus =new Vue()
// 父组件
Vue.component('father',{
    template:"#father",
    data(){
        return {
            fname:'黑山老妖',
        }
    },components: {
        'son':{
            template:"#son",
            data(){
                return {
                    sname:"熊大",
                    mygfname:"翠花"
                }
            },
            methods: {
                tellname(){
                    bus.$emit('getname',this.mygfname)
                }
            }
        },
        'daughter':{
            template:"#daughter",
            data(){
                return {
                    dname:"小熊熊",
                    saozi:''
                }
            },
            mounted () {
                bus.$on('getname',(data)=>{
                    this.saozi=data;
                })
            }
        }
    }
})
    var vm=  new Vue({
        el:"#app",
        data:{


        }
    })
</script>
</html>